/*
@auther fenglei
*/
package xxutil

import (
	"github.com/gogf/gf/v2/net/gipv4"
	"strings"
)

// 获取内网IP地址
func ExternalIP() (string, error) {
	addrs, err := gipv4.GetIpArray()
	if err != nil {
		return "", err
	}
	for _, address := range addrs {
		//判断IP是否为内网IP段
		if gipv4.IsIntranet(address) {
			return address, nil
		}
	}
	return "", nil
}

// 是否是IDC的地址
func IsIDCAddress() (bool, error) {
	addrs, err := ExternalIP()
	if err != nil {
		return false, err
	}
	if strings.Contains(addrs, "192.168") {
		return true, nil
	} else {
		return false, nil
	}
}
